// var i;
// var $eventManager = require("./EventManager");
// var $resKeeper = require("./ResKeeper");
// var $evenType = require("./EvenType");
// var u = cc._decorator;
// var d = u.ccclass;
// var p = (u.property, u.inspector);
// var h = (function (e) {
//     function t() {
//         return (null !== e && e.apply(this, arguments)) || this;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.COMMON_SHAK, this.Shake1, this);
//     };
//     t.prototype.onDisable = function () {
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.COMMON_SHAK, this.Shake1, this);
//     };
//     t.prototype.Shake1 = function () {
//         var e = this;
//         cc.tween(this.node)
//             .by(0.05, {
//                 position: cc.v3(8, 8)
//             })
//             .by(0.05, {
//                 position: cc.v3(-16, -16)
//             })
//             .by(0.05, {
//                 position: cc.v3(8, 8)
//             })
//             .call(function () {
//                 e.node.setPosition(cc.Vec2.ZERO);
//             })
//             .start();
//     };
//     return __decorate([d], t);
// })($resKeeper.default);
// exports.default = h;

import { EventMgrInstance } from './EventManager';
import ResKeeper from './ResKeeper';
import { EVENT_TYPE } from './EvenType';

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：ShakeComponent
 * 处理摇晃动画的组件类
 */
@ccclass
class ShakeComponent extends ResKeeper {
    /**
     * 当组件启用时，添加事件监听器
     * 建议方法名：handleEnable
     */
    onEnable(): void {
        EventMgrInstance.addListener(EVENT_TYPE.COMMON_SHAK, this.executeShake, this);
    }

    /**
     * 当组件禁用时，移除事件监听器
     * 建议方法名：handleDisable
     */
    onDisable(): void {
        EventMgrInstance.removeListener(EVENT_TYPE.COMMON_SHAK, this.executeShake, this);
    }

    /**
     * 执行摇晃动画
     * 建议方法名：executeShake
     */
    // Shake1(): void {
    executeShake(): void {
        const shakeDuration = 0.05;
        const displacement = 8;
        
        cc.tween(this.node)
            .by(shakeDuration, { position: cc.v3(displacement, displacement) })
            .by(shakeDuration, { position: cc.v3(-2 * displacement, -2 * displacement) })
            .by(shakeDuration, { position: cc.v3(displacement, displacement) })
            .call(() => {
                this.node.setPosition(cc.Vec2.ZERO);
            })
            .start();
    }
}

export default ShakeComponent;